home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / tools / dvi_300b / treiber / sources / hp.c < prev    next >
C/C++ Source or Header  |  1995-11-25  |  10KB  |  429 lines

  1. /*********************************************************************
  2. ****    Universaltreiber für HP-kompatible Drucker                ****
  3. *********************************************************************/
  4.  
  5. /* Siehe auch Datei JP350WS.C */
  6.  
  7. #include <atarierr.h>
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include "treiber.h"
  14. #include "portab.h"
  15.  
  16.  
  17. /********************************************************************/
  18. /* Setzt die freien Werte auf Standartwerte */
  19.  
  20. #ifndef OBEN    /* Wenn noch kein oberer Rand definiert */
  21. #define OBEN 0L
  22. #endif
  23.  
  24. #ifndef LINKS    /* Wenn noch kein linker Rand definiert */
  25. #define LINKS 0L
  26. #endif
  27.  
  28. #ifndef MAX_DPI    /* Wenn keine maximale Auflösung definiert */
  29. #define MAX_DPI 1200L
  30. #endif
  31.  
  32. #ifndef WEITE    /* druckbare Breite (in Pixel) */
  33. #define WEITE 9344L
  34. #endif
  35.  
  36. #ifndef HOEHE        /* druckbare Höhe (in Pixel) */
  37. #define HOEHE 13544L
  38. #endif
  39.  
  40. #ifndef EXT
  41. char *drucker_ext="hp";
  42. #else
  43. char *drucker_ext=EXT;
  44. #endif
  45.  
  46. LONG    max_puffer_laenge = 4*WEITE+256;
  47.  
  48. /********************************************************************/
  49.  
  50.  
  51.  
  52. /* Findet entweder Wiederholung (TRUE) oder nichts */
  53. WORD    find_next_same( WORD *rep, UBYTE *p, LONG limit )
  54. {
  55.     WORD    i;
  56.  
  57.         /* Spezialfälle */
  58.     if(  limit<1  )
  59.     {
  60.         *rep = 1;
  61.         return FALSE;
  62.     }
  63.     if( limit<2  &&  p[0]==p[1]  )
  64.     {
  65.         *rep = 2;
  66.         return TRUE;
  67.     }
  68.  
  69.         /* Sonst getrennt */
  70.     if(  p[0]==p[1]  &&  p[1]==p[2]  )
  71.     {
  72.         /* Abstand zum nächsten Ungleichen... */
  73.         i = 3;
  74.         while(  i<128  &&  i<limit  &&  p[0]==p[i]  )
  75.             i++;
  76.         *rep = i;
  77.         return TRUE;
  78.     }
  79.     else
  80.     {
  81.         /* ... bzw. Gleichen ermitteln */
  82.         i = 0;
  83.         while(  i<128  &&  i<limit  &&  !(p[i]==p[i+1]  &&  p[i]==p[i+2])  )
  84.             i++;
  85.         *rep = i;
  86.         return FALSE;
  87.     }
  88. }
  89. /* 17.1.93 */
  90.  
  91.  
  92. static UBYTE    druckzeile[4096];
  93.  
  94.  
  95.  
  96. WORD    drucke_quer( UBYTE *p, LONG start_x, LONG weite, LONG max_zeile, LONG h_dpi, WORD th, WORD flag )
  97. {
  98.     UBYTE    tmp1[50], tmp2[(HOEHE+15)/7], x_offset[10]="", *q;
  99.     LONG    rechts, i, j, x, v_hoehe, v_weite;
  100.     WORD    rep, modus/* Komprimiert oder nicht? */, and;
  101.     extern char    tmp_file[256]; /* In Datei drucken? */
  102.  
  103.     if(  weite+start_x>(HOEHE*h_dpi)/MAX_DPI  )
  104.         v_weite = ((HOEHE-start_x)*h_dpi)/MAX_DPI;
  105.     else
  106.         v_weite = weite;
  107.     weite = ((weite+15)>>4)*2;        /* aufgerundete Byteweite */
  108.  
  109.     /* Nicht druckbarer Rand */
  110.     i = (OBEN*h_dpi)/MAX_DPI;
  111.     p += i*weite;
  112.  
  113.     max_zeile = max_zeile-i-1;
  114.     v_hoehe = max_zeile;
  115.     if(  v_hoehe>(WEITE*h_dpi)/MAX_DPI  )
  116.         max_zeile = (WEITE*h_dpi)/MAX_DPI;
  117.     else
  118.         /* Linken Rand setzen */
  119.         sprintf( x_offset, "%ldx", ((WEITE*h_dpi)/MAX_DPI-max_zeile+7)&0x7FFFFFF8L );
  120.     v_hoehe = (max_zeile+7)>>3;
  121.  
  122.         /* Falls Hoehe nicht durch 8 teilbar */
  123.     and = (WORD)(max_zeile&7);
  124.     if(  and==0  )
  125.         and = 0x00FF;
  126.     else
  127.         and = 0x00FF>>(8-and);
  128.  
  129.         /* Ränder feststellen */
  130.     for(  x=0;  x*8<v_weite  &&  ist_next_leer( p+x, weite, max_zeile );  x++  )
  131.         ;
  132.     x *= 8;
  133.  
  134.     i = 0;
  135.     if(  flag&1  )
  136.     {    /* Evt. Linken Rand abziehen */
  137.         i = (LINKS*h_dpi)/MAX_DPI;
  138.  
  139.         /* In die obere Ecke */
  140.         print_str( " \33*p0Y\33*p-300Y\33*p0X\33*p-300X", th );
  141.     }
  142.  
  143.     if(  x-i>0  )
  144.     {    /* Rand an der linken Seite */
  145.         sprintf( tmp1, "\33*p+%ldY", x-i );
  146.         print_str( tmp1, th ); /*FF*/
  147.     }
  148.     else
  149.         if(  flag&1  )
  150.             x = i;
  151.  
  152.     /* Grafikdruck Anfang */
  153.     /* Grafikauflösung festlegen */
  154.     /* Grafikweite festlegen */
  155.     sprintf( tmp1, "\33&100L\33*rB\33*t%ldR\33*r0A", h_dpi );
  156.     print_str( tmp1, th );
  157.  
  158.     for(  modus=-1;  x<v_weite;  x++  )
  159.     {
  160.         rechts = 0;
  161.         if(  (x&7)==0  ||  modus==-1  )
  162.         {    /* Nächste 8er Zeile: Neue Ränder */
  163.             q = p+(x>>3);
  164.             i = 0;
  165.             while(  i<max_zeile  &&  *q==0  )
  166.             {
  167.                 i++;
  168.                 q += weite;
  169.             }
  170.             if(  i>=max_zeile  )
  171.             {
  172.                 i = x;
  173.                 if(  i>v_weite  )
  174.                     i = v_weite;
  175.                 i = 8-(i&7);
  176.                 sprintf( tmp1, "\33*b%ldY", i );
  177.                 print_str( tmp1, th );
  178.                 x += i;
  179.                 continue;
  180.             }
  181.             else
  182.                 rechts = (i>>3);
  183.         }
  184.  
  185. #ifdef    NO_COMPRESSION
  186.         /* Für LaserJet II & kompatible: Unkomprimiert */
  187.         drehe_90( p, tmp2, weite, v_hoehe-1, x );
  188.         tmp2[0] &= and;
  189.         sprintf( tmp1, "\33*b%liW", v_hoehe );
  190.         print_str( tmp1, th );
  191.         print_block( v_hoehe, tmp2, th );
  192. #else
  193.         /* und den Needle-Warp... */
  194.         drehe_90( p+rechts*8*weite, tmp2, weite, v_hoehe-rechts-1, x );
  195.         tmp2[0] &= and;
  196.  
  197.         /* Wir komprimieren */
  198.         for(  i=0, j=0;  i<v_hoehe-rechts  &&  j<v_hoehe-rechts;  /* Nix! */  )
  199.         {
  200.             if(  find_next_same( &rep, tmp2+i, v_hoehe-i-rechts )  )
  201.             {
  202.                 /* Gleiche */
  203.                 druckzeile[j++] = 1-rep;
  204.                 druckzeile[j++] = tmp2[i];
  205.                 i += rep;
  206.             }
  207.             else
  208.             {
  209.                 /* Ungleiche */
  210.                 druckzeile[j++] = rep-1;
  211.                 while(  rep-->0  )
  212.                     druckzeile[j++] = tmp2[i++];
  213.             }
  214.         }
  215.  
  216.             /* Und nun den interessanten Rest */
  217.         if(  j<v_hoehe-rechts  )
  218.         {
  219.             /* Komprimieren brachte etwas */
  220.             if(  modus!=2  )
  221.                 sprintf( tmp1, "\33*b%s2m%ldW", x_offset, j );
  222.             else
  223.                 sprintf( tmp1, "\33*b%s%ldW", x_offset, j );
  224.             print_str( tmp1, th );
  225.             print_block( j, druckzeile, th );
  226.             modus = 2;
  227.         }
  228.         else
  229.         {
  230.             /* Komprimieren brachte nichts */
  231.             j = v_hoehe-rechts;
  232.             if(  modus!=0  )
  233.                 sprintf( tmp1, "\33*b%s0m%ldW", x_offset, j );
  234.             else
  235.                 sprintf( tmp1, "\33*b%s%ldW", x_offset, j );
  236.             print_str( tmp1, th );
  237.             print_block( j, tmp2, th );
  238.             modus = 0;
  239.         }
  240.         /* 8 Bits fertig */
  241. #endif
  242.     }
  243.  
  244.     /* Ende Grafikmodus */
  245.     /* Ende Seite */    if(  (flag&4)  &&  5!=print_block( 5L, "\33*rB\14", th )  )
  246.         /* Platz reichte nicht aus */        return -1;
  247.     return 0;
  248. }
  249. /* 22.1.93 */
  250.  
  251.  
  252. WORD    drucke( UBYTE *p, LONG start_y, LONG weite, LONG max_zeile, LONG h_dpi, LONG v_dpi, WORD th, WORD flag, WORD quer, UBYTE *optionen )
  253. {
  254.     UBYTE    tmp1[50];
  255.     LONG    max_spalte, zeile, lz, rechts;
  256.     LONG    i, j;
  257.     WORD    rep, modus=0/* Komprimiert oder nicht? */;
  258.  
  259.     if(  flag==4  )
  260.     {    /* Nur Seitenvorschub */
  261.         if(  6!=print_block( 6L, " \33*rB\14", th )  )
  262.             return -1; /*FF*/
  263.     }
  264.  
  265.     if(  h_dpi>700  )
  266.         h_dpi = 1200;
  267.     else if(  h_dpi>350  )
  268.         h_dpi = 600;
  269.     else if(  h_dpi>175  )
  270.         h_dpi = 300;
  271.     else if(  h_dpi>110  )
  272.         h_dpi = 150;
  273.     else if(  h_dpi>80  )
  274.         h_dpi = 100;
  275.     else
  276.         h_dpi = 75;
  277.  
  278.         /* Unsinnige Werte werden als Maximum angenommen */
  279.     if(  h_dpi<=0  ||  h_dpi>MAX_DPI  )
  280.         h_dpi = MAX_DPI;
  281.  
  282.     (void)v_dpi;    /* h_dpi = v_dpi bei HP-kompatiblen! */
  283.     (void)optionen;
  284.  
  285.     if(  quer  )
  286.         return drucke_quer( p, start_y, weite, max_zeile, h_dpi, th, flag );
  287.  
  288.     i = 0;
  289.     if(  flag&1  )
  290.         i = (OBEN*h_dpi)/MAX_DPI;    /* Oberen Rand überspringen */
  291.     j = (LINKS*h_dpi)/MAX_DPI;
  292.     max_spalte = (weite+15)/16;
  293.     max_spalte *= 2;
  294.     p += (max_spalte*i) + j;    /* Nicht druckbare Ränder*/
  295.  
  296.     max_spalte -= j;
  297.     if(  weite>(WEITE+LINKS*8)*h_dpi/MAX_DPI  /* LINKS*8 nicht druckbar!*/  )
  298.         max_spalte = (WEITE*h_dpi)/(8*MAX_DPI);
  299.  
  300.     max_zeile -= i+1;
  301.     max_zeile += start_y;
  302.     if(  max_zeile>(HOEHE*h_dpi)/MAX_DPI  )
  303.         max_zeile = (HOEHE*h_dpi)/MAX_DPI;
  304.     zeile = start_y;
  305.     weite = (weite+15)/16;
  306.     weite *= 2;
  307.  
  308.     /* Ränder feststellen */
  309.     while(  max_spalte>0  &&  ist_next_leer( p+max_spalte-1, weite, max_zeile )  )
  310.         max_spalte--;
  311.  
  312.     if(  flag==4  ||  (flag==7  &&  max_spalte<=1)  )
  313.     {
  314.         /* Seite leer */
  315.         lz = max_zeile-zeile;
  316.         zeile = max_zeile;
  317.     }
  318.  
  319.     if(  flag&1  )
  320.     {    /* In die obere Ecke */
  321.         /* & Grafikauflösung festlegen */
  322.         sprintf( tmp1, " \33*p0Y\33*p-300Y\33*p0X\33*p-300X\33*rB\33*t%ldR", h_dpi );
  323.         print_str( tmp1, th );
  324. #ifndef NO_COMPRESSION
  325.             /* Grafikweite festlegen */
  326.         sprintf( tmp1, "\033*r%lds1A\033*b0M", max_spalte*8 );
  327.         print_str( tmp1, th );
  328. #endif
  329.     }
  330.  
  331.     while(  zeile<max_zeile  &&  (flag&2)  )
  332.      {
  333.              /* Leerzeilen überspringen */
  334.          for(  lz=0;  zeile<max_zeile  &&  ist_leerzeile( p, max_spalte );  lz++, zeile++  )
  335.              p += weite;
  336.          if(  lz>0  )
  337.          {
  338. #ifdef NO_COMPRESSION
  339.             sprintf( tmp1, "\33*p+%ldY", lz );
  340. #else
  341.             sprintf( tmp1, "\33*b%ldY", lz );
  342. #endif
  343.             print_str( tmp1, th );
  344.          }
  345.  
  346.             /* eine oder Druckzeilen an den Drucker! */
  347.         for(  lz=max_zeile;  zeile<lz  &&  zeile<max_zeile  &&  !ist_leerzeile( p, max_spalte );  zeile++  )
  348.         {
  349.             /* Wir komprimieren */
  350.             for(  rechts=1;  rechts<max_spalte  &&  p[max_spalte-rechts]==0;  rechts++  )
  351.                 ;
  352.             rechts--;
  353. #ifndef    NO_COMPRESSION
  354.             for(  i=0, j=0;  i<max_spalte-rechts  &&  j<max_spalte-rechts;  /*Nichts*/  )
  355.             {
  356.                 if(  find_next_same( &rep, p+i, max_spalte-i-rechts )  )
  357.                 {
  358.                     /* Gleiche */
  359.                     druckzeile[j++] = 1-rep;
  360.                     druckzeile[j++] = p[i];
  361.                     i += rep;
  362.                 }
  363.                 else
  364.                 {
  365.                     /* Ungleiche */
  366.                     druckzeile[j++] = rep-1;
  367.                     while(  rep-->0  )
  368.                         druckzeile[j++] = p[i++];
  369.                 }
  370.             }
  371.  
  372.             /* Und nun den interessanten Rest */
  373.             if(  j<max_spalte-rechts  )
  374.             {
  375.                 /* Komprimieren brachte etwas */
  376.                 strcpy( tmp1, "\33*b2m" );
  377.                 ltoa( j, tmp1+3+2-modus, 10 );
  378.                 strcat( tmp1, "W" );
  379.                 print_str( tmp1, th );
  380.                 print_block( j, druckzeile, th );
  381.                 modus = 2;
  382.             }
  383.             else
  384.             {
  385.                 /* Komprimieren brachte nichts */
  386.                 j = max_spalte-rechts;
  387.                 strcpy( tmp1, "\33*b0m" );
  388.                 ltoa( j, tmp1+3+modus, 10 );
  389.                 strcat( tmp1, "W" );
  390.                 print_str( tmp1, th );
  391.                 print_block( j, p, th );
  392.                 modus = 0;
  393.             }
  394. #else
  395.             /* Für LaserJet II & kompatible: Unkomprimiert */
  396.             j = max_spalte-rechts;
  397.             sprintf( tmp1, "\33*b%ldW", j );
  398.             print_str( tmp1, th );
  399.             print_block( j, p+i, th );
  400.             modus = 0;
  401. #endif
  402.             p += weite;
  403.         } /* for */
  404.         lz = 0;
  405.     } /* while */
  406.  
  407.     /* Ende Grafikmodus */
  408.     if(  flag&4  )
  409.     {
  410.         if(  6L!=print_block( 6L, " \33*rB\14", th )  )
  411.             return -1;
  412.     }
  413.     else
  414.         if(  lz>0  )
  415.          {
  416. #ifdef NO_COMPRESSION
  417.             sprintf( tmp1, "\33*p+%ldY", lz );
  418. #else
  419.             sprintf( tmp1, "\33*b%ldY", lz );
  420. #endif
  421.             print_str( tmp1, th );
  422.          }
  423.  
  424.     /* Sollte immer gut gehen! (d.h. kein File zu drucken!) */
  425.     flush_block( th );
  426.     return 0;
  427. }
  428. /* 22.1.93 */
  429.